﻿

namespace Mulala.Cavan.Presentation.Mvc.ViewModel
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Mulala.Cavan.Domain.MainBoundedContext.ProprietorModule;
    using Mulala.Cavan.Presentation.Seedwork;
    using Spring.Context;
    using Spring.Context.Support;
    using Mulala.Cavan.Application.MainBoundedContext.AttachmentModule;
    using Mulala.Cavan.Application.MainBoundedContext.MulalaModule;

    public class ProprietorViewModelConverter
    {
        public static IProprietorViewModel Convert(Proprietor proprietor)
        {
            IApplicationContext springContext = ContextRegistry.GetContext();
            IAttachmentAppService attachmentAppService = springContext.GetObject(MulalaAppServiceConst.ATTACHMENTAPPSERVICE) as IAttachmentAppService;

            IProprietorViewModel proprietorViewModel = ModelFactory.CreateModel<IProprietorViewModel>();
            proprietorViewModel.Item = proprietor;
            proprietorViewModel.Avatar = attachmentAppService.GetProprietorAvatar(ProprietorFactory.CreateProprietor(proprietor.ID));

            return proprietorViewModel;
        }

        public static IList<IProprietorViewModel> Convert(IList<Proprietor> proprietors)
        {
            IList<IProprietorViewModel> proprietorViewModels = new List<IProprietorViewModel>();
            foreach (Proprietor p in proprietors)
            {
                proprietorViewModels.Add(Convert(p));
            }

            return proprietorViewModels;
        }
    }
}
